<div class="layui-fluid nepadmin-pad0 nepadmin-mar0 list0"  lay-title="活动管理">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card layui-tab layui-tab-brief" style="margin: 0;">
                    <ul class="layui-tab-title">
                        <li class="layui-this" value="1" click_num="1">满免活动</li>
                        <li value="2" click_num="1">校园版包机活动</li>
                    </ul>
                    <div class="layui-card-body layui-tab-content hxr-card-body" style="padding: 15px;">
                        <div class="layui-tab-item layui-show" id="bonusset">
                            <div class="layui-card">
                                <div class="layui-card-body">

                                    <div>
                                        <!-- <button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button> -->
                                        <!--				<button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>-->
                                    </div>
                                    <table class="layui-hide" id="list-select-table1" lay-filter="list-select-table1"></table>
                                    <script type="text/html" id="list-tableF1">
                                        <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|停用" lay-filter="list-tableF1"
                                               value="{{ d.status }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.status == '1' ? 'checked' : '' }}>
                                    </script>
                                    <div id="list-toolbar1" style="display: none;">

                                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                                        <!-- 			  {{#if(d.activity_type == 2){ }}
                                                      <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                                                      {{# } }} -->
                                    </div>
                                    <script type="text/html" id="grand_total1">
                                        {{d.grand_total}}{{#if(d.unit == 1){ }}小时{{#  } else{ }}天{{# } }}
                                    </script>
                                    <script type="text/html" id="type1">
                                        {{#if(d.type == 1){ }}
                                        年
                                        {{#  } else if(d.type==2){ }}
                                        季
                                        {{#  } else if(d.type==3){ }}
                                        月
                                        {{#  } else if(d.type==4){ }}
                                        周
                                        {{#  } else if(d.type==5){ }}
                                        日
                                        {{# } }}
                                    </script>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">

                                <div class="layui-card-body">

                                    <div>
                                        <!-- <button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button> -->
                                        <button class="layui-btn layuiadmin-btn-list1" data-type="add1">添加</button>

                                    </div>
                                    <table class="layui-hide" id="list-select-table2" lay-filter="list-select-table2"></table>
                                    <script type="text/html" id="list-tableF2">
                                        <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|停用" lay-filter="list-tableF2"
                                               value="{{ d.status }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.status == '1' ? 'checked' : '' }}>
                                    </script>
                                    <div id="list-toolbar2" style="display: none;">

                                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                                        {{#if(d.activity_type == 2){ }}
                                        <!--                                          <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>-->
                                        {{# } }}
                                    </div>
                                    <script type="text/html" id="grand_total">
                                        {{d.grand_total}}{{#if(d.unit == 1){ }}小时{{#  } else{ }}天{{# } }}
                                    </script>
                                    <script type="text/html" id="type">
                                        {{#if(d.type == 1){ }}
                                        年
                                        {{#  } else if(d.type==2){ }}
                                        季
                                        {{#  } else if(d.type==3){ }}
                                        月
                                        {{#  } else if(d.type==4){ }}
                                        周
                                        {{#  } else if(d.type==5){ }}
                                        日
                                        {{# } }}
                                    </script>
                                </div>

                        </div>

                    </div>


                </div>
            </div>
        </div>
    </div>
</div>
</div>
<style type="text/css">
    #drawingsset .layui-form-label{
        width: 150px;
    }

    #break_set .layui-form-label{
        width: 150px;
    }
    #commission .layui-form-label{
        width: 150px;
    }
    #benefit .layui-form-label{
        width: 150px;
    }
    #applets .layui-form-label{
        width: 150px;
    }
    #opens .layui-form-label{
        width: 150px;
    }
    #drawset .layui-form-label{
        width: 150px;
    }
    #recharge .layui-form-label{
        width: 150px;
    }
    #rechargeset .layui-btn-danger{
        display: inline-block !important;
    }

</style>
<script>
    var formurl='marketing/activeForm',formarea=['500px', '580px'];
    var formurls='marketing/activeForms',formarea=['500px', '680px'];
    layui.use(['table', 'form','element'], function() {
        var table = layui.table,
            form = layui.form,
            $ = layui.$,
            element = layui.element;

        layui.admin.initlist(table,'activity/list',155,[[
            {field:'activity_id', title: 'ID', width:50}


            ,{field:'activity_name', title: '活动名称', width:150}
            ,{field:'type', title: '活动范围', width:150,templet:'#type1'}
            ,{field:'grand_total', title: '满足时间', width:200,templet:'#grand_total1'}

            ,{field:'detail', title: '说明', minWidth:200}
            ,{field:'status', title:'启用/停用', width:100, templet: '#list-tableF1', unresize: true}
            /* ,{field:'create_time', title: '创建时间', width:200} */
            ,{title:'操作', toolbar: '#list-toolbar1',fixed:'right', width:200}
        ]],'#list-select-table1');
        //监听表格表单操作
        form.on('switch(list-tableF1)', function(obj){
            var json = JSON.parse(decodeURIComponent($(this).data('json')));
            json = table.clearCacheKey(json);
            layui.admin.ajax('activity/update',{
                status:json.status==1?2:1,
                activity_id:json.activity_id
            }).then(function(res){
                table.reload('list-select-table1');
            }).catch(function(res){});
        });

        //监听表格操作事件
        table.on('tool(list-select-table1)', function(obj){
            var data = obj.data;
            //删除
            if(obj.event === 'del'){
                layer.confirm('确定删除'+data.activity_name+'?', function(index){
                    layui.admin.delF(table,'activity/delete',{activity_id:data.activity_id},'list-select-table2');
                });
            } else if(obj.event === 'edit'){//编辑
                layui.admin.pupF('编辑活动',formarea,formurl,2,data)
            }
        });
        //监听行双击事件
        /* table.on('rowDouble(list-table)', function(obj){
            //查看详情
            if($('.pay_set').length){
                layui.admin.pupF('支付详情',formarea,formurl,3,obj.data);
            }

        }); */

        //操作dom
        $('.layui-btn.layuiadmin-btn-list').on('click', function(){
            var type = $(this).data('type');
            active111111[type] ? active111111[type].call(this) : '';
        });
        element.on('tab()', function(){
            var item_val=$(this).attr('value')
            if (item_val==1){//
                var formurl='marketing/activeForm',formarea=['500px', '580px'];
                var formurls='marketing/activeForms',formarea=['500px', '680px'];
              //  if ($(this).attr('click_num')!=1) return false;
                $(this).attr('click_num',2);
                layui.admin.initlist(table,'activity/list',155,[[
                    {field:'activity_id', title: 'ID', width:50}


                    ,{field:'activity_name', title: '活动名称', width:150}
                    ,{field:'type', title: '活动范围', width:150,templet:'#type1'}
                    ,{field:'grand_total', title: '满足时间', width:200,templet:'#grand_total1'}

                    ,{field:'detail', title: '说明', minWidth:200}
                    ,{field:'status', title:'启用/停用', width:100, templet: '#list-tableF1', unresize: true}
                    /* ,{field:'create_time', title: '创建时间', width:200} */
                    ,{title:'操作', toolbar: '#list-toolbar1',fixed:'right', width:200}
                ]],'#list-select-table1');
                //监听表格表单操作
                form.on('switch(list-tableF1)', function(obj){
                    var json = JSON.parse(decodeURIComponent($(this).data('json')));
                    json = table.clearCacheKey(json);
                    layui.admin.ajax('activity/update',{
                        status:json.status==1?2:1,
                        activity_id:json.activity_id
                    }).then(function(res){
                        table.reload('list-select-table1');
                    }).catch(function(res){});
                });

                //监听表格操作事件
                table.on('tool(list-select-table1)', function(obj){
                    var data = obj.data;
                    //删除
                    if(obj.event === 'del'){
                        layer.confirm('确定删除'+data.activity_name+'?', function(index){
                            layui.admin.delF(table,'activity/delete',{activity_id:data.activity_id},'list-select-table2');
                        });
                    } else if(obj.event === 'edit'){//编辑
                        layui.admin.pupF('编辑活动',formarea,formurl,2,data)
                    }
                });
                //监听行双击事件
                /* table.on('rowDouble(list-table)', function(obj){
                    //查看详情
                    if($('.pay_set').length){
                        layui.admin.pupF('支付详情',formarea,formurl,3,obj.data);
                    }

                }); */

                //操作dom
                $('.layui-btn.layuiadmin-btn-list').on('click', function(){
                    var type = $(this).data('type');
                    active111111[type] ? active111111[type].call(this) : '';
                });
            }else if (item_val==2){//

                var formurl='marketing/charterform',formarea=['500px', '580px'];
                var formurls='marketing/charterform',formarea=['500px', '680px'];
               // if ($(this).attr('click_num')!=1) return false;
                $(this).attr('click_num',2);
                    layui.admin.initlist(table,'activity/charter_list',155,[[
                        {field:'activity_id', title: 'ID', width:50}
                        ,{field:'device_group_name', title: '设备组', width:200}
                        ,{field:'activity_name', title: '活动名称', width:150}
                        ,{field:'grand_total', title: '时间（天）', width:200,templet:'#grand_total'}
                        ,{field:'price', title: '价格', width:100}
                        ,{field:'detail', title: '说明', minWidth:200}
                        ,{field:'status', title:'启用/停用', width:100, templet: '#list-tableF2', unresize: true}
                        /* ,{field:'create_time', title: '创建时间', width:200} */
                        ,{title:'操作', toolbar: '#list-toolbar2',fixed:'right', width:200}
                    ]],'#list-select-table2');
                    //监听表格表单操作
                    form.on('switch(list-tableF2)', function(obj){
                        var json = JSON.parse(decodeURIComponent($(this).data('json')));
                        json = table.clearCacheKey(json);
                        layui.admin.ajax('activity/update',{
                            status:json.status==1?2:1,
                            activity_id:json.activity_id
                        }).then(function(res){
                            table.reload('list-select-table2');
                        }).catch(function(res){});
                    });

                    //监听表格操作事件
                    table.on('tool(list-select-table2)', function(obj){
                        var data = obj.data;
                        //删除
                        if(obj.event === 'del'){
                            layer.confirm('确定删除'+data.activity_name+'?', function(index){
                                layui.admin.delF(table,'activity/delete',{activity_id:data.activity_id});
                            });
                        } else if(obj.event === 'edit'){//编辑
                            layui.admin.pupF('编辑活动',formarea,formurl,2,data)
                        }
                    });
                    //监听行双击事件
                    /* table.on('rowDouble(list-table)', function(obj){
                        //查看详情
                        if($('.pay_set').length){
                            layui.admin.pupF('支付详情',formarea,formurl,3,obj.data);
                        }

                    }); */
                    var active = {
                        //多行删除
                        batchdel:function(){
                            layui.admin.delsF(table,'payment/pay_type_delete','pay_type_id','list-select-table2')
                        }
                        //添加
                        ,add1: function(othis){
                            layui.admin.pupF('添加活动',formarea,formurls,1,{})
                        }
                    };
                    //操作dom
                    $('.layui-btn.layuiadmin-btn-list1').on('click', function(){
                        var type = $(this).data('type');
                        active[type] ? active[type].call(this) : '';
                    });
            }

            //   return false;

        });
    })
</script>